package com.example.naodian.config;

import com.example.naodian.interceptor.JwtTokenAdminInterceptor;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@AllArgsConstructor
@Slf4j
public class WebConfig implements WebMvcConfigurer {
    private final JwtTokenAdminInterceptor jwtTokenAdminInterceptor;

    /**
     * 注册自定义拦截器
     *
     * @param registry
     */
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("开始注册自定义拦截器...");
        registry.addInterceptor(jwtTokenAdminInterceptor)
                .addPathPatterns("/user/**")
                .addPathPatterns("/eeg/eeg-data-block/**")
                .addPathPatterns("/warning/**")
                .addPathPatterns("/eeg-recording/**")
                .excludePathPatterns("/eeg/eeg-data-block/list")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/reg");
    }
}
